package cn.stu.cms.controller;


import cn.stu.cms.dto.PageDto;
import cn.stu.cms.pojo.Menu;
import cn.stu.cms.service.MenuService;
import cn.stu.cms.util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 菜单控制器
 *
 * @author gh
 * @date 2023/09/18
 */
@RestController
@RequestMapping("/menu")
@AllArgsConstructor
public class MenuController {

    private MenuService service;


    /**
     * 列表
     *
     * @param page  页面
     * @param title 标题
     * @param pid   PID
     * @return {@link R}<{@link PageDto}<{@link Menu}>>
     */
    @GetMapping(value = "/page")
    public R<PageDto<Menu>> page(PageDto<Menu> page, @RequestParam(required = false) String title, @RequestParam(required = false) Long pid) {
        return service.menuList(page, title, pid);
    }

    /**
     * 删除
     *
     * @param id ID
     * @return {@link R}<{@link String}>
     */
    @DeleteMapping(value = "/delete/{id}")
    public R<String> delete(@PathVariable("id") Long id) {
        return service.menuDel(id);
    }




    /**
     * 添加
     *
     * @param rs RS
     * @return {@link R}
     */
    @PostMapping(value = "/save")
    public R<String> add(@RequestBody @Valid Menu rs) {
        return service.menuAdd(rs);
    }

    /**
     * 更新
     *
     * @param rs RS
     * @return {@link R}
     */
    @PutMapping(value = "/edit")
    public R<String> update(@RequestBody @Valid Menu rs) {
        return service.menuUpdate(rs);
    }

}

